package com.yaoweigroup.community.adapter;

import java.util.List;

import com.yaoweigroup.community.R;
import com.yaoweigroup.community.enity.Repair;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class OnlineAdapter extends BaseAdapter {

	private Context context;
	private List<Repair> list;
	private LayoutInflater mInflater;

	public OnlineAdapter(Context context, List<Repair> list) {
		mInflater = LayoutInflater.from(context);
		this.context = context;
		this.list = list;
	}

	@Override
	public int getCount() {
		return list.size();
	}

	@Override
	public Object getItem(int position) {
		return list.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		Holder holder;
		if (convertView == null) {
			holder = new Holder();
			convertView = mInflater.inflate(R.layout.adapter_online_my_item,
					null);
			convertView.setTag(holder);
			holder.name_tv = (TextView) convertView.findViewById(R.id.name_tv);
			holder.num_tv = (TextView) convertView.findViewById(R.id.num_tv);
			holder.time_tv = (TextView) convertView.findViewById(R.id.time_tv);
			holder.reson_tv = (TextView) convertView
					.findViewById(R.id.reson_tv);
			holder.state_tv = (TextView) convertView
					.findViewById(R.id.state_tv);
		} else {
			holder = (Holder) convertView.getTag();
		}
		Repair repair = list.get(position);
		holder.num_tv.setText(position + 1 + "");
		holder.name_tv.setText(repair.getContent());
		holder.time_tv.setText(repair.getAddTime());
		String strState = "";
		switch (repair.getState()) {
		case 0:
			strState = "未受理";
			break;
		case 1:
			strState = "受理中";
			break;
		case 2:
			strState = "已处理";
			break;
		case 3:
			strState = "受理未通过";
			break;
		}
		holder.state_tv.setText("状态:" + strState);
		if (repair.getStatenote() != null) {
			holder.state_tv.setText("原因:" + repair.getStatenote());
		}
		return convertView;
	}

	public final class Holder {

		TextView name_tv;
		TextView num_tv;
		TextView time_tv;
		TextView state_tv;
		TextView reson_tv;
	}

	public void setDataChange(List<Repair> list) {
		this.list = list;
		notifyDataSetChanged();
	}

}
